package com.jiyun.service;

import com.jiyun.bean.User;
import com.jiyun.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public List<User> findAll() {
        return userMapper.selectAll();
    }

    @Transactional
    public void add(User user) {
        userMapper.insertSelective(user);
    }

    @Transactional
    public void update(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Transactional
    public void delete(Integer id) {
        userMapper.deleteByPrimaryKey(id);
    }

    public User findById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }
}
